import { useAmendAddress } from "../../hook/amendAddress.js";
import { Space, Card, Breadcrumb, Form, Input, Button, Radio ,message} from 'antd';// ui组件
import { useHistory } from "react-router-dom";



export default () => {
  
    const history = useHistory();
    // 修改数据的hoock
    const [{ _id, name, Address, longitude, latitude, Cold_store, Phone, Open_hours }, {amend_address}] = useAmendAddress()
 

    //点击修改获取表单内的value值
    const onFinish = async (values) => {
     //合并当前的_id 和value值
        const newAddress={...values,_id}
    //调用hoock内的修改自提点方法, 发请求 拿到修改成功的的状态值
       const state= await amend_address(newAddress)
      if(state){
        message.info('修改成功,即将跳转至自提点列表',2,()=>history.push("/info/address"))
 
      }
    };

    const onFinishFailed = (errorInfo) => {
        console.log('Failed:', errorInfo);
    };





    return <Space direction="vertical" style={{ width: "100%" }}>
        <Card >
            <Breadcrumb>
                <Breadcrumb.Item>主页</Breadcrumb.Item>
                <Breadcrumb.Item>自提点</Breadcrumb.Item>

                <Breadcrumb.Item>
                    <a href="/#/info/amendAddress" style={{ fontSize: "16px", color: "black" }}>修改自提点</a>
                </Breadcrumb.Item>
            </Breadcrumb>
        </Card>
        <Card title="新增自提点">
            <Space direction="vertical" style={{ width: 500 }}>
                <Form
                    name="address"
                    labelCol={{
                        span: 8,
                    }}
                    wrapperCol={{
                        span: 16,
                    }}
                    initialValues={{
                        remember: true,
                    }}
                    onFinish={onFinish}
                    onFinishFailed={onFinishFailed}
                    autoComplete="off"
                >
                    <Form.Item
                        label="自提点名称"
                        name="name"
                        initialValue={name}
                    >
                        <Input />
                    </Form.Item>
                    <Form.Item
                        label="自提点地址"
                        name="Address"
                        initialValue={Address}
                    >
                        <Input />
                    </Form.Item>
                    <Form.Item
                        label="自提点经度"
                        name="longitude"
                        initialValue={longitude}
                    >
                        <Input />
                    </Form.Item>
                    <Form.Item
                        label=" 自提点纬度"
                        name="latitude"
                        initialValue={latitude}
                    >
                        <Input />
                    </Form.Item>
                    <Form.Item
                        label="储存条件"
                        name="Cold_store"
                        initialValue={Cold_store}
                    >
                        <Radio.Group>
                            <Radio value={true}>冷冻</Radio>
                            <Radio value={false}>非冷冻</Radio>

                        </Radio.Group>
                    </Form.Item>
                    <Form.Item
                        label="联系电话"
                        name="Phone"
                        initialValue={Phone}
                    >
                        <Input />
                    </Form.Item>
                    <Form.Item
                        label="营业时间"
                        name="Open_hours"
                        initialValue={Open_hours}
                    >
                        <Input />
                    </Form.Item>
                    <Form.Item
                        wrapperCol={{
                            offset: 8,
                            span: 16,
                        }}
                    >
                        <Button type="primary" htmlType="submit">
                            修改
                        </Button>
                    </Form.Item>
                </Form>

            </Space>
        </Card>
    </Space>

}